export const onAnimateIntersectionObserver = (
  entries: IntersectionObserverEntry[]
) => {
  entries.forEach((entry) => {
    if (entry.isIntersecting) {
      const target = entry.target as HTMLElement;
      target.classList.add("animate__animated");
      if (target.dataset?.animate) {
        target.classList.add(`animate__${target.dataset.animate}`);
      }
      if (target.dataset?.animateDelay) {
        target.style.setProperty(
          "--animate-duration",
          target.dataset.animateDelay
        );
      }

      // 当动画结束后，移除相应 class
      target.addEventListener(
        "animationend",
        () => {
          target.classList.remove("animate__animated");
          if (target.dataset?.animate) {
            target.classList.remove(`animate__${target.dataset.animate}`);
          }
        },
        { once: true }
      );
    }
  });
};
